<?php
/**
 * Created by PhpStorm.
 * User: Mloong
 * Date: 2019/4/15
 * Time: 11:40
 */

namespace app\common\validate;


use app\lib\exception\ParameterException;

class PhoneValidate
{
    public function checkPhone($arr)
    {
        if(is_array($arr) == false){
            throw new ParameterException([
                'code' => '400',
                'msg' => 'mush be array'
            ]);
        }
        foreach ($arr as $phone){
            if($this->preg_match_phone($phone) == false){
                throw new ParameterException([
                   'code' => '400',
                   'msg' => '手机号码格式错误'
                ]);
            }
        }
        return $arr;
    }
    private function preg_match_phone($phone)
    {
        return preg_match("/^1[3456789]\d{9}$/", $phone) ? true : false;
    }
}